'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 排行榜记录
 * @author sundbcn@gmail.com (sun debing)
 */

var mongoConnector = require('../libs/mongodb/mongoConnector');
/* jshint unused:false */
var rebelRecordSchema = require('../schemas/rebelRecordSchema');
var RebelRecord = mongoConnector().model('RebelRecord');
var dataApi = require('../libs/dataApi');

var rebelRecordModel = module.exports;

rebelRecordModel.addRecord = function (atk_role_id, rebel_id, atk_data, def_data, cb) {
    // 创建成功后
    function afterCreate(err, model) {
        cb(err, model);
    }

    RebelRecord.create({
        atk_role_id: atk_role_id,
        rebel_id: rebel_id,
        atk: atk_data,
        def: def_data
    }, afterCreate);
};

/**
 * 获取一个战斗记录
 */
rebelRecordModel.getRecordByAtkRoleId = function (atk_role_id, record_id, cb) {
    RebelRecord.findById(record_id, function (err, rank_record_model) {
        if (!!rank_record_model && rank_record_model.getAtkRoleId() != atk_role_id) {
            cb();
        } else {
            cb(null, rank_record_model);
        }
    });
};
